package com.ruoyi.coal.modules.coalpile.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.coal.modules.coalpile.domain.AttributeValue;
import com.ruoyi.coal.modules.coalpile.domain.vo.YardPileDataVo;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface AttributeValueMapper extends BaseMapper<AttributeValue> {
    @Select({"SELECT p.pile_id, a.id AS attribute_id, a.name AS attribute_name, COALESCE(v.value_string, '0') AS value_string FROM (SELECT DISTINCT pile_id FROM cp_coal_attribute_value) p CROSS JOIN cp_coal_attribute a LEFT JOIN cp_coal_attribute_value v ON p.pile_id = v.pile_id AND a.id = v.attribute_id ORDER BY p.pile_id, a.id "})
    List<Map<String, Object>> getAttributeValue();

    @Select({"SELECT yp.yard_id, yp.pile_id,COALESCE(( SELECT value_string FROM cp_coal_attribute_value cav WHERE cav.yard_id = yp.yard_id AND cav.pile_id = yp.pile_id AND cav.attribute_id = 29 LIMIT 1 ), '0' ) AS weight FROM ( SELECT DISTINCT yard_id, pile_id  FROM cp_coal_attribute_value  ) AS yp ORDER BY yp.yard_id, yp.pile_id"})
    List<YardPileDataVo> selectAllPileTon();
}

